﻿//
// Copyright (c) 2024 BPer
//
#ifndef BPer_BPerAudioCaptureWindows_H1
#define BPer_BPerAudioCaptureWindows_H1
#include <bperaudiodev/win/BPerRecAudioCaptureHandle.h>
#include <bperaudiodev/BPerAudioCapture.h>

#include <bperavutil/audio/BPerPreProcess.h>
#include <bperavutil/audio/BPerAudioMix.h>
#include <bperavutil/audio/BPerRtcAec.h>
#if BPer_OS_WIN

#include <amstream.h>
#include <control.h>
#include <qedit.h>

class BPerAudioCaptureWindows: public BPerAudioCapture {
public:
    BPerAudioCaptureWindows(BPerAVInfo *avinfo);
	~BPerAudioCaptureWindows();

public:
    BPerRecAudioCaptureHandle *m_ahandle;

    int32_t init();
	void setInAudioBuffer(vector<BPerAudioPlayBuffer*> *pal);
	void setPreProcess(BPerPreProcess *pp);
	void setCatureStart();
	void setCatureStop();
    void setOutAudioBuffer(BPerAudioBuffer *pbuffer);
	void setPlayAudoBuffer(BPerAudioBuffer *pbuffer);
    void setAec(BPerRtcAec *paec);

protected:

	void startLoop();

	void stopLoop();
private:

	int32_t m_isInit;
	int32_t m_ret;
	void setPara();
	void getBaseFilter(const GUID gi,IBaseFilter *ib,int32_t ind);
	HRESULT GetUnconnectPin(IBaseFilter * pFilter,PIN_DIRECTION dir,IPin **ppPin);
	IPin * FindPin(IBaseFilter * pFilter,PIN_DIRECTION dir);
	IPin * FindPin1(IBaseFilter * pFilter,PIN_DIRECTION dir);
	HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum);

private:

	int32_t m_size;
	int32_t m_loops;
	int32_t m_channel;
	uint32_t  m_sample;
	int32_t m_frames;

	AM_MEDIA_TYPE *m_mt;
	IMediaControl *m_pm;
	IGraphBuilder *m_pg;
	ICaptureGraphBuilder2 *m_pb;

	IBaseFilter *m_audioSrc;
	IBaseFilter *m_nullRender;

	IMoniker   *m_moniker;
	ISampleGrabber *m_grabber;
    IBaseFilter *m_grabberF;
    IMediaEventEx *m_event;
};

#endif
#endif
